package com.yidu.qianfeng.common.bean.company;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author: TangSheng
 * @Description: 员工信息实体,实现security中的UserDetails接口
 * @since 1.0
 * @Date Created in 16:06 2021/3/3
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("table_emp_info")
public class EmpInfo implements UserDetails {

    @TableId
    private String empAccount;//员工账号

    private String empPassword;//员工密码，使用了BCryptPasswordEncoder加密

    private char empAccountStatus;//员工账号状态

    private String empName;//员工姓名

    private String empSubstId;//员工分站id,可以为空

    private String empTelephone;//员工手机号

    private String empJobnumber;//员工工号

    private String empSex;//员工性别

    private String empDepartment;//员工所属部门，可以为空

    private String empWorkplace;//员工职位

    private String empEducation;//员工学历

    private String empSalary;//员工薪水

    private String empHomeAddress;//员工家庭住址

    private String empHomePhone;//员工家庭电话

    private String empIdnumber;//员工身份证

    private String empBirhdate;//员工生日

    private String empJoindate;//员工入职日期

    private int empDataAuth;//员工数据权限级别

    @TableField(exist = false)
    private List<ModelAuth> modelAuth; //员工模块权限（模块中间表）

    @TableField(exist = false)
    private List<EmpModel> empModel; //权限模块(子表)

    @TableField(exist = false)
    private List<EmpAuth> empAuth; //员工权限关联（中间表）

    @TableField(exist = false)
    private List<EmpPage> empPage; //页面权限(子表)

    @TableField(exist = false)
    private Subst subst;


    @TableField(exist = false)//不存在表中
    private Collection<? extends GrantedAuthority> authorities;//权限集合


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.getEmpPassword();
    }

    @Override
    public String getUsername() {
        return this.getEmpAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;

    }

    @Override
    public boolean isAccountNonLocked() {
        if (this.getEmpAccountStatus() == 0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        if (this.getEmpAccountStatus() == 0){
            return false;
        }else {
            return true;
        }
    }
}
